// Drawing mixins

// generic drawing of more complex things


// shadows

// based shadow values:
// https://material-design.storage.googleapis.com/images/layout-principles-dimensionality-shadows-08_large_mdpi.png

// box-shadow 1px blur doesn't draw correctly, see
// https://bugzilla.gnome.org/show_bug.cgi?id=738484
// $z-depth-1: 0 1px 1.5px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.24);

$z-depth-light: 0 1px 1px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.20);
$z-depth-dark: 0 1px 1px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
$z-depth-1: if($headerbar =='light', $z-depth-light, $z-depth-dark);
$z-depth-2: 0 3px 3px rgba(0, 0, 0, 0.16), 0 3px 3px rgba(0, 0, 0, 0.23);
$z-depth-3: 0 10px 10px rgba(0, 0, 0, 0.19), 0 6px 3px rgba(0, 0, 0, 0.23);
$z-depth-4: 0 10px 10px rgba(0, 0, 0, 0.25), 0 5px 5px rgba(0, 0, 0, 0.22);
$z-depth-5: 0 19px 19px rgba(0, 0, 0, 0.30), 0 15px 6px rgba(0, 0, 0, 0.22);

$depth_light: 0 1px 1px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.20);

$header_shadow: if($headerbar =='light', $depth_light, $z-depth-dark);

// ripple effect animations

@keyframes ripple_effect {
  to { background-size: 1000% 1000%; }
}

@keyframes scale_ripple_effect {
  to { background-size: auto, 1000% 1000%; }
}

@keyframes header_ripple_effect {
  from {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $primary_color 0%,
                                      transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $primary_color 100%,
                                      transparent 0%);
  }
}

@mixin entry($t, $fc:$primary_color) {
//
// Entries drawing function
//
// $t: entry type
// $fc: focus color
//
// possible $t values:
// normal, focus, disabled, flat-normal, flat-focus, flat-disabled;
//

  @if $t == normal {
    transition: $shorter_transition, $shadow_transition;
    border: none;
    border-image: none;
    box-shadow: $z-depth-1;
    background-color: if($fc != $primary_color, $fc, $base_color);
    color: if($fc != $primary_color, $inversed_fg_color, $secondary_fg_color);
  }

  @if $t == focus {
    border: none;
    border-image: none;
    box-shadow: $z-depth-2;
    color: if($fc != $primary_color, $inversed_fg_color, $fg_color);
  }

  @if $t == disabled {
    box-shadow: $z-depth-1;
    background-color: $alt_base_color;
    color: $disabled_fg_color;
  }

  @if $t == fallback-normal {
    border: 1px solid $darker_borders_color;
    box-shadow: none;
    border-image: none;
    border-radius: 2px;
    background-color: if($fc != $primary_color, $fc, $base_color);
    color: if($fc != $primary_color, $inversed_fg_color, $secondary_fg_color);
  }

  @if $t == fallback-focus {
    border: 1px solid $primary_color;
    box-shadow: none;
    border-image: none;
    border-radius: 2px;
    background-color: if($fc != $primary_color, $fc, $base_color);
    color: if($fc != $primary_color, $inversed_fg_color, $fg_color);
  }

  @if $t == fallback-disabled {
    border: 1px solid $darker_borders_color;
    box-shadow: none;
    border-image: none;
    background-color: $alt_base_color;
    color: $disabled_fg_color;
  }

  @if $t == flat-normal {
    transition: $shorter_transition;
    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $fc 0%,
                                  transparent 0%)
                                  0 0 0 / 0 0 0px;
    box-shadow: inset 0 -1px if($fc != $primary_color, $fc, $track_color);
    background-color: transparent;
    color: $fg_color;
  }

  @if $t == flat-focus {
    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $fc 100%,
                                  transparent 0%)
                                  0 0 2 / 0 0 2px;
    box-shadow: inset 0 -1px if($fc != $primary_color, $fc, $track_color);
  }

  @if $t == flat-disabled {
    box-shadow: inset 0 -1px $track_color;
    background-color: transparent;
    color: $disabled_fg_color;
  }
}


@mixin button($t, $c:$lighter_bg_color, $tc:$fg_color) {
//
// Button drawing function
//
// $t:    button type,
// $c:    base button color for colored* types
// $tc:   optional text color for colored* types
//
// possible $t values:
// normal, hover, active, disabled, checked, checked-disabled,
// flat-normal, flat-hover, flat-active, flat-disabled, flat-checked, flat-checked-disabled;
//

  @if $t == normal {
    transition: $shorter_transition,
                $shadow_transition,
                background-size $ripple_duration $deceleration_curve,
                background-image $ripple_opacity_duration $deceleration_curve;
    box-shadow: $z-depth-1, inset 0 0 0 9999px transparent;
    background-color: $c;
    background-image: radial-gradient(circle farthest-corner at center,
                                      transparent 100%,
                                      transparent 0%);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 1000% 1000%;
    color: $secondary_fg_color;
    border: none;
  }

  @if $t == hover {
    box-shadow: $z-depth-2, inset 0 0 0 9999px transparent;
    color: $fg_color;
    background-color: lighten($lighter_bg_color, 5%);
  }

  @if $t == active {
    transition: $shorter_transition,
                background-size 0,
                background-image 0;
    animation: ripple_effect $shorter_duration $deceleration_curve forwards;
    box-shadow: $z-depth-2, inset 0 0 0 9999px $semi_track_color;
    background-image: radial-gradient(circle farthest-corner at center,
                                      $semi_track_color 10%,
                                      transparent 0%);
    background-size: 0% 0%;
    color: $fg_color;
  }

  @if $t == disabled {
    box-shadow: none;
    background-color: $semi_track_color;
    color: if($tc != $fg_color, $disabled_fg_color, $disabled_secondary_fg_color);
  }

  @if $t == checked {
    background-color: $primary_color;
    color: $inversed_fg_color;
  }

  @if $t == checked-disabled {
    background-color: $track_color;
    color: scale-alpha($primary_color, $disabled_opacity);
  }

  // flat buttons
  @if $t == flat-normal {
    transition: $shorter_transition,
                background-size $ripple_duration $deceleration_curve,
                background-image $ripple_opacity_duration $deceleration_curve;
    box-shadow: inset 0 0 0 9999px transparent;
    background-color: transparent;
    background-image: radial-gradient(circle farthest-corner at center,
                                      transparent 100%,
                                      transparent 0%);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 1000% 1000%;
    color: $secondary_fg_color;
  }

  @if $t == flat-hover {
    box-shadow: inset 0 0 0 9999px $semi_track_color;
    color: $fg_color;
  }

  @if $t == flat-active {
    transition: $shorter_transition,
                background-size 0,
                background-image 0;
    animation: ripple_effect $shorter_duration $deceleration_curve forwards;
    box-shadow: inset 0 0 0 9999px $semi_track_color;
    background-image: radial-gradient(circle farthest-corner at center,
                                      $semi_track_color 10%,
                                      transparent 0%);
    background-size: 0% 0%;
    color: $fg_color;
  }

  @if $t == flat-disabled {
    box-shadow: none;
    background-color: transparent;
    color: if($tc != $fg_color, gtkalpha(currentColor, $disabled_opacity), gtkalpha(currentColor, $enabled_opacity * $disabled_opacity));
  }

  @if $t == flat-checked {
    color: $fg_color;
    background-color: rgba($fg_color, 0.20);
  }

  @if $t == flat-checked-disabled {
    background-color: rgba($fg_color, 0.15);
    color: $disabled_fg_color;
  }

  // fallback buttons
  @if $t == fallback-normal {
    border: 1px solid $darker_borders_color;
    box-shadow: none;
    background-color: $c;
    color: $secondary_fg_color;
  }

  @if $t == fallback-hover {
    box-shadow: none;
    background-color: mix($c, $fg_color, 96%);
    color: $fg_color;
  }

  @if $t == fallback-active {
    box-shadow: none;
    background-color: mix($c, $fg_color, 92%);
    color: $fg_color;
    animation: none;
  }

  @if $t == fallback-disabled {
    box-shadow: none;
    background-color: mix($bg_color, $fg_color, 96%);
    color: $fg_color;
  }

  @if $t == fallback-checked {
    box-shadow: none;
    background-color: $primary_color;
    color: $inversed_fg_color;
  }

  @if $t == fallback-checked-disabled {
    box-shadow: none;
    background-color: rgba($primary_color, 0.5);
    color: $tertiary_inversed_fg_color;
  }

  // headerbar buttons
  @if $t == header-normal {
    transition: none;
    animation: none;
    box-shadow: none;
    background-color: transparent;
    color: $secondary_headerbar_fg_color;
  }

  @if $t == header-hover {
    transition: $shorter_transition,
                background-size 0,
                background-image 0;
    animation: none;
    box-shadow: inset 0 0 0 9999px rgba($primary_color, 0.3);
    background-image: radial-gradient(circle farthest-corner at center,
                                      rgba($primary_color, 0.3) 10%,
                                      transparent 0%);
    background-size: 0% 0%;
    color: $theme_color;
  }

  @if $t == header-active {
    transition: $shorter_transition,
                background-size 0,
                background-image 0;
    animation: ripple_effect $shorter_duration $deceleration_curve forwards;
    box-shadow: inset 0 0 0 9999px $primary_color;
    background-image: radial-gradient(circle farthest-corner at center,
                                      $primary_color 10%,
                                      transparent 0%);
    background-size: 0% 0%;
    color: $inversed_fg_color;
  }

  @if $t == header-disabled {
    box-shadow: none;
    background-color: transparent;
    color: if($tc != $fg_color, gtkalpha(currentColor, $disabled_opacity), gtkalpha(currentColor, $enabled_opacity * $disabled_opacity));
  }

  @if $t == header-checked {
    background-color: $primary_color;
    color: $inversed_fg_color;
  }

  @if $t == header-checked-hover {
    background-color: lighten($primary_color, 5%);
    background-image: none;
    box-shadow: none;
  }

  @if $t == header-checked-disabled {
    background-color: rgba($primary_color, $disabled_opacity);
    color: gtkalpha(currentColor, $disabled_opacity);
  }
}

@mixin overshoot($p, $t:normal, $c:$alt_primary_color) {
//
// overshoot
//
// $p: position
// $t: type
// $c: base color
//
// possible $p values:
// top, bottom, right, left
//
// possible $t values:
// normal, backdrop
//

  $_position: center $p;

  @if ($p == left) or ($p == right) {
    $_position: $p center;
  }

  background-image: -gtk-gradient(radial,
                                  $_position, 0,
                                  $_position, 0.75,
                                  to(scale-alpha($c, $lower_opacity)),
                                  to(transparent));

  background-repeat: no-repeat;
  background-position: $_position;

  background-color: transparent; // reset some properties to be sure to not inherit them somehow
  border: none;                  //
  box-shadow: none;              //
}


@mixin undershoot($p) {
//
// undershoot
//
// $p: position
//
// possible $p values:
// top, bottom, right, left
//

  $_undershoot_color_dark: scale-alpha($fg_color, $lower_opacity);
  $_undershoot_color_light: scale-alpha($base_color, $lower_opacity);

  $_gradient_dir: left;
  $_dash_bg_size: 12px 1px;
  $_gradient_repeat: repeat-x;
  $_bg_pos: left $p;

  background-color: transparent; // shouldn't be needed, but better to be sure;

  @if ($p == left) or ($p == right) {
    $_gradient_dir: top;
    $_dash_bg_size: 1px 12px;
    $_gradient_repeat: repeat-y;
    $_bg_pos: $p top;
  }

  background-image: linear-gradient(to $_gradient_dir, // this is the dashed line
                                    $_undershoot_color_light 50%,
                                    $_undershoot_color_dark 50%);

  padding-#{$p}: 1px;
  background-size: $_dash_bg_size;
  background-repeat: $_gradient_repeat;
  background-origin: content-box;
  background-position: $_bg_pos;
}
